<template>
	<!-- 大客户项目报备管理  -主要内容维护-->
	<div class="wrapper">
		<!-- <Loding :isLoding.sync="isMinLoding" :lodingClass="'loding01'"> -->
			<!-- <Loding :isLoding.sync="isLoding" :lodingClass="'loding02'"> -->
		<!-- <Anchor class="lodingBox" :labelList="labels" style="min-height:360px;" activeId="row-01"  labelWidth="130"> -->
			<!-- <div class="line" style="min-height:700px" id="row-01"> -->
				<BreakSpace label="基本信息" :containerStyle="{ marginBottom: '10px' }" />
				<BasicInfo ref="basicFrom" :formType="infoType" v-model="formData" @formchange="basicFromChange"/>
			<!-- </div>
			<div class="line" style="min-height:510px" id="row-02"> -->
				<BreakSpace label="项目信息" :containerStyle="{ marginBottom: '10px' }" />
				<ProjectInfo ref="projectForm" :formType="infoType" v-model="formData" @formchange="projectFormChange"/>
			<!-- </div>
			<div class="line" style="min-height:310px" id="row-03"> -->
				<BreakSpace label="竞争对手分析" :containerStyle="{ marginBottom: '10px' }" />
				<OpponentInfo ref="opponentForm" :formType="infoType" v-model="formData" @formchange="opponentFormChange"/>
			<!-- </div>
			<div class="line" id="row-04"> -->
				<BreakSpace label="联系人信息" :containerStyle="{ marginBottom: '10px' }" />
				<ContactInfo ref="contactFrom" :formType="infoType" v-model="formData" @formchange="contactFromChange"/>
			<!-- </div>
			<div class="line" id="row-05"> -->
				<BreakSpace label="意向车型需求信息" :containerStyle="{ marginBottom: '10px' }" />
				<CarInfo ref="carForm" :formType="infoType" v-model="formData" @formchange="carFormChange"/>
			<!-- </div> -->
		<!-- </Anchor> -->
		<BreakSpace label="审核意见" :containerStyle="{ marginBottom: '10px' }" />
		<IdeaInfo ref="ideaInfo" v-model="ideaInfoData" style="margin-top:10px;" @close="examineClose"/>
			<!-- </Loding> -->
		<div class="dialogBottmView">
			<el-button @click="closeDialog">关 闭</el-button>
			<el-button @click="submitDialog(1)" type="primary" v-if="infoType != 'show'">提交</el-button>
			<el-button @click="submitDialog(-1)" type="primary" v-if="infoType != 'show'">保存</el-button>
		</div>
		<!-- </Loding> -->
	</div>
</template>

<script>
	// import Loding from '@/utils/loding'; //等待框
	//api和类型
	import { getDealerCompanyByCode } from '@/api/common/org/dealerCompany';
	import { getReview,saveReview,addAllFrom,editAllFrom } from '@/api/cms-api/customerManage/approvalManage/DLR';
	import * as apiType from '@/api/cms-api/customerManage/approvalManage/types';

	import { authority } from '@/utils/authMixin';
	import { dictionary } from '@/utils/dictMixin';
	import autoLoding from '@/utils/loding';//等待框

	import BasicInfo from './infoBase'; //基本信息
	import ProjectInfo from './infoProject'; //项目信息
	import OpponentInfo from './infoOpponent'; //竞争对手
	import ContactInfo from './infoContact'; //联系人信息
	import CarInfo from './infoCar'; //意向车型需求信息
	import IdeaInfo from './infoIdea'; //审核意见和附件

	export default {
		name: 'DealerCompany',
		mixins: [authority, dictionary, autoLoding],
		components: {
			BasicInfo,
			ProjectInfo,
			OpponentInfo,
			ContactInfo,
			CarInfo,
			IdeaInfo
		},
		props: {
			value: {
				type: Number,
				required: true
			},
			infoType: {
				type: String,
				required: true
			},
			isExamine: {
				type: Boolean,
				required: true
			},
			examineType: {
				type: Number,
				required: true
			},
		},
		data() {
			return {
				// isMinLoding:false,
				// isLoding:true,
				// labels: [
				// 	{ title: '基本信息', id: 'row-01' },
				// 	{ title: '项目信息', id: 'row-02' },
				// 	{ title: '竞争对手分析', id: 'row-03' },
				// 	{ title: '联系人信息', id: 'row-04' },
				// 	{ title: '意向车型需求信息', id: 'row-05' },
				// ],
				formData: {
					allForm: {
						majorProjectContactList:[],
						majorProjectModelList:[],
					},
					majorProjectContact:{
						list:[],
						total:0
					},
					majorProjectModel:{
						list:[],
						total:0
					}
				},
				ideaInfoData:{
					projectId: this.value,
					examineFormData:{},
					infoBasic:this.isExamine?'edit':'view',
					isOk:this.isOk,
					examineType:this.examineType
				}
			};
		},
		mounted(){
			this.loadingVm = this.openLoding('.cover-container');
			if(this.infoType != 'add'){
				this.init();
			}else{
				this.closeLoding(this.loadingVm);
				// this.isLoding = false;
			}
		},
		methods: {
			//初始化数据
			async init(){
				//按ID查询数据
				let id = this.value;
				await getReview(id,{}).then(res=>{
					if(res.resultCode === 200){
						this.formData.allForm = res.data;
						this.ideaInfoData.formData = this.formData;
						this.$nextTick(() =>{
							this.$refs.basicFrom.init();
							this.$refs.projectForm.init();
							this.$refs.opponentForm.init();
							this.$refs.contactFrom.init();
							this.$refs.carForm.init();
							this.$refs.ideaInfo.initFormData();
							this.closeLoding(this.loadingVm);
							// this.isLoding = false;
						});
					}
				});
			},
			basicFromChange(data){
				this.$refs.projectForm.saveDialog();
			},
			projectFormChange(data){
				this.$refs.opponentForm.saveDialog();
			},
			opponentFormChange(data){
				this.$refs.contactFrom.saveDialog();
			},
			contactFromChange(data){
				this.$refs.carForm.saveDialog();
			},
			carFormChange(data){
				this.loadingVm = this.openLoding('.cover-container');
				// this.isMinLoding = true;
				if(this.submitType === 1){
					//设置为提交
					this.formData.allForm.projectStatus = apiType.PROJECT_STATUS_REVIEW;
				}else{
					//设置为保存
					this.formData.allForm.projectStatus = apiType.PROJECT_STATUS_SAVED;
				}
				this.save(this.formData.allForm,this.submitType);
			},
			examineClose(data){},
			//审核子页关闭事件
			examineClose(){
				this.$emit('close', '');
			},
			//保存(不验证)
			saveDialog(type) {
				this.loadingVm = this.openLoding('.cover-container');
				// this.isMinLoding = true;
				//直接提取数据
				let allData = Object.assign({},this.formData.allForm);
				//@1
				this.$refs.basicFrom.$refs.FormPanel.excuteFormData(this.$refs.basicFrom.$refs.FormPanel.form);
				allData = Object.assign(allData,this.$refs.basicFrom.$refs.FormPanel.form);

				//@2
				this.$refs.projectForm.$refs.FormPanel.excuteFormData(this.$refs.projectForm.$refs.FormPanel.form);
				allData = Object.assign(allData,this.$refs.projectForm.$refs.FormPanel.form);

				//@3
				this.$refs.opponentForm.$refs.FormPanel.excuteFormData(this.$refs.opponentForm.$refs.FormPanel.form);
				allData = Object.assign(allData,this.$refs.opponentForm.$refs.FormPanel.form);

				//@4
				Object.assign(this.$refs.contactFrom.pdata.allForm.majorProjectContactList,this.$refs.contactFrom.pdata.majorProjectContact.list);
				allData = Object.assign(allData,this.$refs.contactFrom.pdata);

				//@5
				Object.assign(this.$refs.carForm.pdata.allForm.majorProjectModelList,this.$refs.carForm.pdata.majorProjectModel.list);
				allData = Object.assign(allData,this.$refs.carForm.pdata);

				//设置为保存
				allData.projectStatus = apiType.PROJECT_STATUS_SAVED;
				//设置为已生效
				// allData.projectFollowUpStatus = apiType.PROJECT_FOLLOW_UP_STATUS_EFFECTIVE;

				this.save(allData,2);
			},
			submitDialog(type){
				this.submitType = type;
				//调取idea子页组件的
				this.$refs.basicFrom.saveDialog();
			},
			//取消操作
			closeDialog() {
				this.$emit('close', { visible: false });
			},
			async save(allData,type){
				// let formData = Object.assign({},this.formData);
				let res = {};
				if(this.infoType === 'add'){
					//补充DEALER_CODE 与DEALER_NAME
					// allData.dealerCode = ;
					// allData.dealerName = ;
					res = await addAllFrom(allData);
				}else{
					let id = this.value;
					res = await editAllFrom(id,allData);
				}
				if(res.resultCode === 200){
					this.$notify.success({title: '提示信息',message:type == 1?'提交成功':'保存成功'});
					this.closeLoding(this.loadingVm);
					// this.isMinLoding = false;
					this.$emit('close', 'refresh');
				}else{
					this.$notify.error({title: '提示信息',message:res.errMsg});
					this.closeLoding(this.loadingVm);
				}
			},
		}
	}
</script>

<style scoped>
	#row-04,#row-05{
		height: auto;
		min-height: 100%
	}
	/* .wrapper,.line{
		height: calc(100vh - 135px);
	} */
	.wrapper,.line{
		/* height: calc(100vh - (110px + 180px)); */
		height: calc(100vh - 110px);
	}
	.drawer-content{
		height: calc(100% - 160px);
	}
	.line{
		overflow-x:hidden;
		overflow-y:auto;
	}
</style>
